// 存储忘记密码后的操作状态
import { CHANGEFORGETPASSWDACTIVATE, DOFORGETPASSWD } from '../constants'

const initState = {
    // 忘记密码后的弹窗
    forgetPasswdState: {
        activate: false
    },
    // 修改密码是否成功
    doForgetPasswdState: {
        success: false,
        captcha_error: false,
        email_error: false
    }
}

export default function ForgetPasswdReducer (preState=initState, action) {
    const { type, data } = action
    switch (type) {
        case CHANGEFORGETPASSWDACTIVATE:
            return {
                ...preState,
                forgetPasswdState: Object.assign({}, preState.forgetPasswdState, data)
            }
        case DOFORGETPASSWD:
            return {
                ...preState,
                doForgetPasswdState: Object.assign({}, preState.doForgetPasswdState, data)
            }
        default:
            // return {...preState} // 会导致数据持久化失效
            var state = preState
            return state
    }
}